//package com.xiguaji.tiktok.task.aweme.event;
//
//import com.google.common.eventbus.AllowConcurrentEvents;
//import com.google.common.eventbus.Subscribe;
//import com.gugee.tiktok.common.model.dal.blogger.BloggerLogRepository;
//import com.gugee.tiktok.common.model.dal.blogger.BloggerMainRepository;
//import com.gugee.tiktok.common.model.dto.SlimBloggerDto;
//import com.gugee.tiktok.common.model.mysql.BloggerLog;
//import com.xiguaji.boot.eventbus.Event;
//import com.xiguaji.boot.eventbus.EventBusTemplate;
//import com.xiguaji.boot.eventbus.IEventListener;
//import com.xiguaji.boot.toolkit.ThreadPoolUtils;
//import com.xiguaji.tiktok.task.aweme.AwemeService;
//import com.xiguaji.tiktok.task.awemecomment.event.SaveAwemeCommentEventListener;
//import com.xiguaji.tiktok.task.monitor.LogUtil;
//import com.xiguaji.tiktok.task.monitor.Monitor;
//import lombok.SneakyThrows;
//import lombok.extern.slf4j.Slf4j;
//import lombok.val;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Lazy;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//
//import java.util.List;
//import java.util.Optional;
//import java.util.concurrent.ExecutionException;
//import java.util.concurrent.ForkJoinPool;
//import java.util.stream.Collectors;
//
//@Component
//@Slf4j
//public class RefreshAwemeKeywordEventListener implements IEventListener<RefreshAwemeKeywordEventListener.RefreshAwemeKeywordEvent> {
//    @Autowired
//    BloggerLogRepository bloggerLogRepository;
//
//    @Autowired
//    BloggerMainRepository bloggerMainRepository;
//
//    @Autowired
//    @Lazy
//    EventBusTemplate eventBusTemplate;
//
//    @Autowired
//    AwemeService awemeService;
//
//    @SneakyThrows
//    @Override
//    @Subscribe
//    @AllowConcurrentEvents
//    public void handle(RefreshAwemeKeywordEvent event) {
//        run(event);
//    }
//
//    public void run(RefreshAwemeKeywordEvent event){
//        int bloggerLogType = BloggerLog.BloggerLogType.REFRESH_BLOGGER_AWEME_KEYWORD.getValue();
//
//        Optional<BloggerLog> bloggerLogOptional = bloggerLogRepository.findByLogType(bloggerLogType);
//        BloggerLog bloggerLog;
//
//        int page = 1;
//        if (bloggerLogOptional.isPresent()) {
//            page = (int)bloggerLogOptional.get().getCurrentBloggerId();
//            bloggerLog = bloggerLogOptional.get();
//        } else {
//            bloggerLog = new BloggerLog();
//            bloggerLog.setLogType(bloggerLogType);
////            bloggerLog.setExtValue("");
//            bloggerLog.setCreateBy(event.getSource());
//            bloggerLog.setUpdateBy(event.getSource());
//        }
//
//        List<SlimBloggerDto> bloggers = bloggerMainRepository.findSlimBloggersScoreAndCount((page-1)*500, 500);
//        if (CollectionUtils.isEmpty(bloggers)) {
//            bloggerLog.setCurrentBloggerId(1);
//            bloggerLogRepository.save(bloggerLog);
//            return;
//        }
//
//        bloggerLog.setCurrentBloggerId(page + 1);
//        bloggerLogRepository.save(bloggerLog);
//
//        val bloggerIds = bloggers.stream().map(SlimBloggerDto::getUid).collect(Collectors.toList());
//        // redis日志记录
//        LogUtil.setCountSize(bloggerIds.size());
//
//        SaveAwemeKeywordEventListener.SaveAwemeKeywordEvent saveAwemeKeywordEvent = new SaveAwemeKeywordEventListener.SaveAwemeKeywordEvent(bloggerIds);
//        eventBusTemplate.post(saveAwemeKeywordEvent);
//    }
//
//    public static class RefreshAwemeKeywordEvent extends Event {
//
//        public RefreshAwemeKeywordEvent() {
//            super("RefreshAwemeKeywordEvent");
//        }
//    }
//}
